package com.azkj.album.view.fragment;

import static android.content.Context.CLIPBOARD_SERVICE;

import android.Manifest;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import com.azkj.album.R;
import com.azkj.album.adapter.ListAdapter;
import com.azkj.album.dto.BannerBean;
import com.azkj.album.dto.CategoryBean;
import com.azkj.album.dto.DyShareIdAndDescAndTitle;
import com.azkj.album.dto.ListData;
import com.azkj.album.dto.MessageEvent;
import com.azkj.album.dto.MessageType;
import com.azkj.album.network.ConfigStorage;
import com.azkj.album.network.Constants;
import com.azkj.album.network.NetworkMaster;
import com.azkj.album.network.callback.ServiceCallback;
import com.azkj.album.network.networkframe.bean.BaseResp;
import com.azkj.album.network.networkframe.net.exception.ApiException;
import com.azkj.album.network.utils.ToastUtils;
import com.azkj.album.presenter.BannerPresenter;
import com.azkj.album.utils.GlideImageLoader;
import com.azkj.album.utils.PermissionsUtils;
import com.azkj.album.utils.ShareUtils;
import com.azkj.album.view.activity.DetailActivity;
import com.azkj.album.view.activity.MainCollectActivity;
import com.azkj.album.view.activity.SearchActivity;
import com.azkj.album.view.activity.WebViewActivity;
import com.azkj.album.view.base.BaseActivity;
import com.azkj.album.view.base.BaseFragment;
import com.azkj.album.view.iview.IBannerView;
import com.azkj.album.view.widgets.dialog.ColorChooseDialog;
import com.azkj.album.view.widgets.dialog.CommonDialog;
import com.azkj.album.view.widgets.dialog.DialogHelper;
import com.azkj.album.view.widgets.staggedrv.GridItemDecoration;
import com.azkj.album.view.widgets.staggedrv.StaggerdRecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.youth.banner.Banner;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MainFragment extends BaseFragment implements IBannerView {

    @BindView(R.id.scrollView)
    NestedScrollView scrollView;
    @BindView(R.id.rv_main)
    StaggerdRecyclerView mRecyclerView;

    @BindView(R.id.bv_main)
    Banner mBanner;

    @BindView(R.id.refreshLayout)
    SmartRefreshLayout mRefreshLayout;
    @BindView(R.id.tv_to_top)
    TextView ivTop;
    @BindView(R.id.tv_drop_mark)
    TextView mTvCategory;
    @BindView(R.id.ll_del_default)
    View mRlDeleteDefault;
    @BindView(R.id.ll_delete)
    View mLlDelete;
    @BindView(R.id.tv_del_1)
    TextView mTvOpt1;
    @BindView(R.id.tv_del_2)
    TextView mTvOpt2;
    @BindView(R.id.tv_del_3)
    TextView mTvOpt3;
    @BindView(R.id.tv_del_4)
    TextView mTvOpt4;
    @BindView(R.id.tv_del_5)
    TextView mTvOpt5;
    @BindView(R.id.tv_del_6)
    TextView mTvOpt6;
    @BindView(R.id.tv_del_7)
    TextView mTvOpt7;
    @BindView(R.id.tv_del_8)
    TextView mTvOpt8;
    @BindView(R.id.tv_finish)
    TextView tvFinish;

    private ListAdapter mAdapter;
    private List<String> imgUrlList = new ArrayList<>();
    private BannerPresenter mBannerPresenter;
    private int mPage = 1;
    private String keyword = "";
    private String categoryId = "";
    private int limit = 10;

    private int curShareType = 0;//分享封面0  分享图册1

    private boolean isCanSelect = false;
    private PermissionsUtils permissionsUtils = new PermissionsUtils();
    private List<CategoryBean> datas = new ArrayList<>();
    private CategoryBean curCategory = new CategoryBean();

    private int notifyIndex = -1;

    @Override
    protected int getLayoutId() {
        return R.layout.fragemnt_main;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        initListener();
        loadData();
        getCategory();
    }

    @Override
    public void onVisible() {
        super.onVisible();
        loadData();
    }

    private void initView() {
        mBannerPresenter = new BannerPresenter(this);
        mAdapter = new ListAdapter();
        mAdapter.setHasStableIds(true);
        mRecyclerView.link(mAdapter, 2);
        mAdapter.bindToRecyclerView(mRecyclerView.rv);
        mAdapter.setEmptyView(R.layout.list_empty);
        mRecyclerView.addDecoration(new GridItemDecoration(getContext(), 10));
        RecyclerView.ItemAnimator animator = mRecyclerView.rv.getItemAnimator();
        if (animator instanceof SimpleItemAnimator) {
            ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
        }
        // 第二种，设置动画时间为0
        mRecyclerView.rv.getItemAnimator().setChangeDuration(0);
        mAdapter.setOnItemClickListener((adapter, view, position) -> {
            ListData item = mAdapter.getData().get(position);
            if (isCanSelect) {
                if (curShareType == 1){
                    //单选
                    mAdapter.getSelList().clear();
                    mAdapter.getSelList().add(String.valueOf(item.getId()));
                    mAdapter.notifyDataSetChanged();
                }else{
                    if (mAdapter.getSelList().contains(String.valueOf(item.getId()))) {
                        mAdapter.getSelList().remove(String.valueOf(item.getId()));
                    } else {
                        mAdapter.getSelList().add(String.valueOf(item.getId()));
                    }
                    if (curShareType == 0){
                        if (mAdapter.getSelList().size() > 1){
                            mTvOpt5.setVisibility(View.GONE);
                            if (mAdapter.getSelList().size() > 9){
                                mTvOpt4.setVisibility(View.GONE);
                            }else {
                                mTvOpt4.setVisibility(View.VISIBLE);
                            }
                        }else {
                            mTvOpt5.setVisibility(View.VISIBLE);
                        }
                    }
                    if (curShareType == 2){
                        if (!mAdapter.getSelList().isEmpty()) {
                            mTvOpt8.setText("确认删除（" + mAdapter.getSelList().size() + ")");
                        } else {
                            mTvOpt8.setText("确认删除");
                        }
                    }
                    mAdapter.notifyItemChanged(position);
                }

//                mAdapter.notifyItemChanged(position);
            } else {
                notifyIndex = position;
                Intent intent = new Intent(getActivity(), DetailActivity.class);
                intent.putExtra("detail", item);
                intent.putExtra("fromType", DetailActivity.FROM_TYPE_MAIN);
                startActivity(intent);
            }
        });

    }

    private void initListener() {

        scrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
            ivTop.setVisibility(scrollY < 300 ? View.GONE : View.VISIBLE);
            //Log.d("xxxxx", "scrollY = " + scrollY);
        });

        mRefreshLayout.setEnableAutoLoadMore(false);
        mRefreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                mPage++;
                getDataList();

            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                mPage = 1;
                getDataList();
            }
        });
    }


    private void loadData() {
        DialogHelper.showFailDialog("加载中", 0);
        mBannerPresenter.getBanner();
        getDataList();
    }

    @OnClick({R.id.tv_search, R.id.tv_to_top, R.id.tv_drop_mark, R.id.iv_collects, R.id.ll_del_default, R.id.iv_delete_dismiss, R.id.tv_del_1, R.id.tv_del_2, R.id.tv_del_3, R.id.tv_del_4, R.id.tv_del_5, R.id.tv_del_6, R.id.tv_del_7, R.id.tv_del_8})
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_to_top:
                scrollView.smoothScrollTo(0, 0);
                ivTop.setVisibility(View.GONE);
                break;
            case R.id.iv_collects:
                startActivity(new Intent(getActivity(), MainCollectActivity.class));
                break;
            case R.id.tv_drop_mark:
                new ColorChooseDialog.Builder(getActivity()).setChoosetList(datas).setChooseData(curCategory).setOnClickListener((dialog, position) -> {
                    dialog.dismiss();
                    curCategory = datas.get(position);
                    mTvCategory.setText(curCategory.getName());
                    categoryId = curCategory.getId();
                    if ("-1".equals(categoryId)) {
                        categoryId = "";
                    }
                    mPage = 1;
                    getDataList();
                }).show();
                break;
            case R.id.ll_del_default:
                mRlDeleteDefault.setVisibility(View.GONE);
                mLlDelete.setVisibility(View.VISIBLE);
                mTvOpt1.setVisibility(View.VISIBLE);
                mTvOpt2.setVisibility(View.VISIBLE);
                mTvOpt3.setVisibility(View.VISIBLE);
                break;
            case R.id.iv_delete_dismiss:
            case R.id.tv_del_7:
                mRlDeleteDefault.setVisibility(View.VISIBLE);
                mLlDelete.setVisibility(View.GONE);
                mTvOpt1.setVisibility(View.GONE);
                mTvOpt2.setVisibility(View.GONE);
                mTvOpt3.setVisibility(View.GONE);
                mTvOpt4.setVisibility(View.GONE);
                mTvOpt5.setVisibility(View.GONE);
                mTvOpt6.setVisibility(View.GONE);
                mTvOpt7.setVisibility(View.GONE);
                mTvOpt8.setVisibility(View.GONE);
                hideSelectedShade();
                break;
            case R.id.tv_del_1:
                curShareType = 0;
                isCanSelect = true;
                mTvOpt1.setVisibility(View.GONE);
                mTvOpt2.setVisibility(View.GONE);
                mTvOpt3.setVisibility(View.GONE);
                mTvOpt4.setVisibility(View.VISIBLE);
                mTvOpt5.setVisibility(View.VISIBLE);
                mTvOpt6.setVisibility(View.VISIBLE);
                mTvOpt7.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_del_2:
                curShareType = 1;
                isCanSelect = true;
                mTvOpt1.setVisibility(View.GONE);
                mTvOpt2.setVisibility(View.GONE);
                mTvOpt3.setVisibility(View.GONE);
                mTvOpt4.setVisibility(View.VISIBLE);
                mTvOpt5.setVisibility(View.VISIBLE);
                mTvOpt6.setVisibility(View.VISIBLE);
                mTvOpt7.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_del_3:
                curShareType = 2;
                isCanSelect = true;
                mTvOpt1.setVisibility(View.GONE);
                mTvOpt2.setVisibility(View.GONE);
                mTvOpt3.setVisibility(View.GONE);
                mTvOpt7.setVisibility(View.VISIBLE);
                mTvOpt8.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_del_4:
                //分享微信好友
                shareWX();
                break;
            case R.id.tv_del_5:
                //分享微信朋友圈
                shareWXCircleOfFriends();
                break;
            case R.id.tv_del_6:
                //分享抖音
                shareDY();
                break;
            case R.id.tv_del_8:
                //确认删除
                delGallerys();
                break;
            case R.id.tv_search:
                Intent intent = new Intent(getActivity(), SearchActivity.class);
                intent.putExtra("pageType", 0);
                startActivity(new Intent(intent));
                break;
        }
    }

    /**
     * 隐藏选择图册的遮罩
     */
    private void hideSelectedShade(){
        isCanSelect = false;
        ArrayList<Integer> adapterNotifyPosition = getAdapterNotifyPosition();
        mAdapter.getSelList().clear();
        mTvOpt8.setText("确认删除");
        if (!adapterNotifyPosition.isEmpty()){
            for (Integer integer : adapterNotifyPosition) {
                mAdapter.notifyItemChanged(integer);
            }
        }
    }

    private ArrayList<Integer> getAdapterNotifyPosition(){
        ArrayList<Integer> positions = new ArrayList<>();
        List<ListData> data = mAdapter.getData();
        List<String> selList = mAdapter.getSelList();
        if (!data.isEmpty() && !selList.isEmpty()){
            for (int i = 0; i < data.size(); i++) {
                for (String s : selList) {
                    if (s.equals(String.valueOf(data.get(i).getId()))){
                        positions.add(i);
                    }
                }
            }
        }
        return positions;
    }

    private void shareWX(){
        if (curShareType == 0){
            if (mAdapter.getSelList().size() == 1){
                onlyShareSingleCover();
                ((BaseActivity)getActivity()).shareImageToWx(null,getCoverImages().get(0), true,-1);
            }else if (mAdapter.getSelList().size() > 1){
                ((BaseActivity)getActivity()).shareImageToWxMore(getCoverImagesAndName());
            }else {
                ToastUtils.showCenterToast("请先选择图册");
            }
        }else {
            if (mAdapter.getSelList().size() == 1){
                onlyShareSingleCover();
                ((BaseActivity)getActivity()).shareWeb(getChooseImage().get(0), false,
                        Constants.WEB_PAGE_SHARE_TASK + getShareIdAndName().shareId,
                        getShareIdAndName().shareTitle,getShareIdAndName().shareDesc);
            }else {
                ToastUtils.showCenterToast("请先选择图册");
            }
        }
    }

    private void shareWXCircleOfFriends(){
        if (curShareType == 0){
            if (mAdapter.getSelList().size() == 1){
                onlyShareSingleCover();
                ((BaseActivity)getActivity()).shareImageToWx(null,getCoverImages().get(0), false,-1);
            }else if (mAdapter.getSelList().size() == 0){
                ToastUtils.showCenterToast("请先选择图册");
            }
        }else {
            if (mAdapter.getSelList().size() == 1){
                onlyShareSingleCover();
                ((BaseActivity)getActivity()).shareWeb(getChooseImage().get(0),true,
                        Constants.WEB_PAGE_SHARE_TASK + getShareIdAndName().shareId,
                        getShareIdAndName().shareTitle,getShareIdAndName().shareDesc);
            }else {
                ToastUtils.showCenterToast("请先选择图册");
            }
        }
    }

    private void shareDY(){
        if (curShareType == 0){
            if (mAdapter.getSelList().size() == 1){
                onlyShareSingleCover();
                ((BaseActivity)getActivity()).shareImgToDy(null,getCoverImagesAndName().get(0).first, getCoverImagesAndName().get(0).second,-1);
            }else if (mAdapter.getSelList().size() > 1){
                ((BaseActivity)getActivity()).shareImgToDyMore(getCoverImagesAndName());
            }else {
                ToastUtils.showCenterToast("请先选择图册");
            }
        }else {
            if (mAdapter.getSelList().size() == 1){
                onlyShareSingleCover();
                ((BaseActivity)getActivity()).shareImgToDyMore(getCoverImgAndAlbumImgs());
            }else {
                ToastUtils.showCenterToast("请先选择图册");
            }
        }
    }

    private ArrayList<Pair<String, String>> getCoverImgAndAlbumImgs(){
        ArrayList<Pair<String, String>> pairs = new ArrayList<>();
        if (mAdapter.getSelList().size() == 1) {
            for (ListData datum : mAdapter.getData()) {
                if (mAdapter.getSelList().get(0).equals(String.valueOf(datum.getId()))) {
                    pairs.add(new Pair<>(datum.getCoverImage(), String.valueOf(datum.getId())));
                    for (String s1 : datum.getImages().split(",")) {
                        int lastSlashIndex = s1.lastIndexOf("/");
                        String result = s1.substring(lastSlashIndex + 1);
                        pairs.add(new Pair<>(s1, result));
                    }
                }
            }
        }
        return pairs;
    }

    private void onlyShareSingleCover(){
        Pair<String, String> pair = getIntroAndRemark().get(0);
        Log.d(TAG, "onlyShareSingleCover: " + pair.first + " === "+ pair.second);
        String intro = getIntroAndRemark().get(0).first;
        if (TextUtils.isEmpty(intro)) {
            String remark = getIntroAndRemark().get(0).second;
            if (!TextUtils.isEmpty(remark)) {
                copyToClipboard(remark);
            }
        } else {
            copyToClipboard(intro);
        }
    }

    private ArrayList<Pair<String, String>> getIntroAndRemark(){
        ArrayList<Pair<String, String>> pairs = new ArrayList<>();
        for (ListData datum : mAdapter.getData()) {
            for (String s : mAdapter.getSelList()) {
                if (s.equals(String.valueOf(datum.getId()))){
                    pairs.add(new Pair<>(datum.getIntro(), datum.getRemark()));
                }
            }
        }
        return pairs;
    }

    private DyShareIdAndDescAndTitle getShareIdAndName(){
        DyShareIdAndDescAndTitle dyShareIdAndDescAndTitle = new DyShareIdAndDescAndTitle();
        if (mAdapter.getSelList().size() == 1){
            for (ListData datum : mAdapter.getData()) {
                for (String s : mAdapter.getSelList()) {
                    if (s.equals(String.valueOf(datum.getId()))){
                        dyShareIdAndDescAndTitle.shareId = datum.getShareId();
                        dyShareIdAndDescAndTitle.shareTitle = datum.getIntro();
                        dyShareIdAndDescAndTitle.shareDesc = datum.getRemark();
                    }
                }
            }
        }
        return dyShareIdAndDescAndTitle;
    }

    private ArrayList<String> getChooseImage(){
        ArrayList<String> coverImages = new ArrayList<>();
        for (ListData datum : mAdapter.getData()) {
            for (String s : mAdapter.getSelList()) {
                if (s.equals(String.valueOf(datum.getId()))){
                    coverImages.add(datum.getChooseImage());
                }
            }
        }
        return coverImages;
    }

    private ArrayList<String> getCoverImages(){
        ArrayList<String> coverImages = new ArrayList<>();
        for (ListData datum : mAdapter.getData()) {
            for (String s : mAdapter.getSelList()) {
                if (s.equals(String.valueOf(datum.getId()))){
                    coverImages.add(datum.getCoverImage());
                }
            }
        }
        return coverImages;
    }

    private ArrayList<Pair<String, String>> getCoverImagesAndName(){
        ArrayList<Pair<String, String>> pairs = new ArrayList<>();
        for (ListData datum : mAdapter.getData()) {
            for (String s : mAdapter.getSelList()) {
                if (s.equals(String.valueOf(datum.getId()))){
                    pairs.add(new Pair<>(datum.getCoverImage(), String.valueOf(datum.getId())));
                }
            }
        }
        return pairs;
    }


    @Subscribe
    public void onMessage(MessageEvent messageEvent) {
        super.onMessage(messageEvent);
        switch (messageEvent.getType()) {
            case MessageType.TYPE_ON_DETAIL_DEL:
                if (null != mAdapter && -1 != notifyIndex) {
                    mAdapter.remove(notifyIndex);
                    notifyIndex = -1;
                }
                break;
            case MessageType.TYPE_ON_COLLECT_CANCEL:
            case MessageType.TYPE_ON_MAIN_RECOVERY:
            case MessageType.TYPE_ON_SAVE_SUCCESS:
                mPage = 1;
                getDataList();
                break;
        }
    }


    @Override
    public void getBannerSuccess(List<BannerBean> data) {

        imgUrlList.clear();
        if (data == null | data.size() == 0) {
            mBanner.setVisibility(View.GONE);
            return;
        }

        for (BannerBean bean : data) {
            imgUrlList.add(bean.getImgurl());
        }
        mBanner.setVisibility(View.VISIBLE);
        mBanner.isAutoPlay(true).setImageLoader(new GlideImageLoader()).setOnBannerListener(position -> {
            BannerBean bannerBean = data.get(position);
            mBannerPresenter.clickBanner(bannerBean.getId());
            if (TextUtils.isEmpty(bannerBean.getUrl())) return;
            Intent intent = new Intent(getContext(), WebViewActivity.class);
            intent.putExtra("title", bannerBean.getTitle());
            intent.putExtra("url", bannerBean.getUrl());
            intent.putExtra("shareTiTle", bannerBean.getTitle());
            intent.putExtra("isShowShare", true);
            startActivity(intent);
        }).setImages(imgUrlList).start();


    }

    @Override
    public void getBannerFail(String msg) {
        mBanner.setVisibility(View.GONE);
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        permissionsUtils.onRequestPermissionsResult(getActivity(), requestCode, permissions, grantResults);
    }

    public void getDataList() {
        NetworkMaster.getInstance().getCommonService().getList(ConfigStorage.getInstance().getToken(), String.valueOf(mPage), String.valueOf(limit), keyword, categoryId, "", "", new ServiceCallback<BaseResp<List<ListData>>>() {
            @Override
            public void onSuccess(BaseResp data) {
                DialogHelper.hideDialog();
                mRefreshLayout.finishLoadMore(true);
                mRefreshLayout.finishRefresh(true);
                if (data.getCode() == 1) {
                    List<ListData> list = (List<ListData>) data.getData();
                    if (mPage == 1) {
                        mAdapter.setNewData(list);
                    } else {
                        mAdapter.addData(list);
                    }
                    //处理数据
                    if (list.size() < limit) {
                        tvFinish.setVisibility(View.VISIBLE);
                        new CountDownTimer(3000, 1000){

                            @Override
                            public void onTick(long millisUntilFinished) {

                            }

                            @Override
                            public void onFinish() {
                                tvFinish.setVisibility(View.GONE);
                            }
                        }.start();
                        mRefreshLayout.setEnableLoadMore(false);
                    } else {
                        tvFinish.setVisibility(View.GONE);
                        mRefreshLayout.setEnableLoadMore(true);
                    }
                } else {
                    ToastUtils.showCenterToast(data.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                DialogHelper.hideDialog();
                mRefreshLayout.finishLoadMore(true);
                mRefreshLayout.finishRefresh(true);
                ToastUtils.showCenterToast(apiException.errorInfo.error);
            }

        });
    }

    private void getCategory() {
        NetworkMaster.getInstance().getCommonService().mainCategory(new ServiceCallback<BaseResp<List<CategoryBean>>>() {
            @Override
            public void onSuccess(BaseResp<List<CategoryBean>> jsonObj) {
                curCategory.setId("-1");
                curCategory.setName("全部");
                datas.add(curCategory);
                datas.addAll(jsonObj.getData());
            }

            @Override
            public void onError(ApiException apiException) {
                ToastUtils.showCenterToast(apiException.errorInfo.error);
            }
        });
    }

    private void delGallerys() {
        new CommonDialog.Builder(getActivity()).setDesc("是否删除选中图册").setButton("取消", "确定").setBackground(R.mipmap.ic_login_error).setOnClickListener((dialog, confirm) -> {
            if (confirm) {
                StringBuilder idsSb = new StringBuilder();
                for (String id : mAdapter.getSelList()) {
                    idsSb.append(id + ",");
                }
                NetworkMaster.getInstance().getCommonService().mainDel(ConfigStorage.getInstance().getToken(), idsSb.toString(), new ServiceCallback() {
                    @Override
                    public void onSuccess(Object jsonObj) {
                        for (String id : mAdapter.getSelList()) {
                            ListData item = mAdapter.getItemById(id);
                            int position = mAdapter.getItemPosition(item);
                            mAdapter.notifyItemRemoved(position);
                            mAdapter.getData().remove(item);
                        }
                        mAdapter.getSelList().clear();
                        mTvOpt8.setText("确认删除");
                        EventBus.getDefault().post(new MessageEvent(MessageType.TYPE_ON_MAIN_DEL));
                        mTvOpt7.callOnClick();
                    }

                    @Override
                    public void onError(ApiException apiException) {
                        ToastUtils.showCenterToast(apiException.errorInfo.error);
                    }
                });
            }
            dialog.dismiss();
        }).show();

    }

    public void copyToClipboard(String text){
        ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
        if(clipboard != null){
            ClipData clip = ClipData.newPlainText("text", text);
            clipboard.setPrimaryClip(clip);
            ToastUtils.showCenterToast("相册简介/相册备注已复制到剪切板！");
        }
    }
}
